package cn.venny.clickhouse.config;

import cn.venny.clickhouse.properties.ClickHouseCustomProperties;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import ru.yandex.clickhouse.ClickHouseDataSource;

/**
 * @author vick
 * @version 1.0
 * <p></p> 2021/5/29 14:30</p>
 */
@Configuration
public class ClickHouseConfig {

//    private static final String SLAVE_MAPPER_LOCATION = "classpath*:mapper/**/*.xml";

    @Bean
    public ClickHouseDataSource getClickHouseDataSource(ClickHouseCustomProperties properties) {
        return new ClickHouseDataSource(properties.getUrl(), properties);
    }

    /**
     * 分页插件
     */
    @Bean
    public MybatisPlusInterceptor paginationInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 解决分页 total = 0 的问题
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.CLICK_HOUSE));
        return interceptor;
    }
}
